package com.appcheck.recording.action.impl;

import java.util.Iterator;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.view.View;

import com.appcheck.recording.action.AbstractAction;
import com.appcheck.recording.action.ActionConvert;
import com.appcheck.recording.action.DefaultAction;
import com.appcheck.recording.handler.AbstractActionHandler;
import com.appcheck.recording.model.IdNamePair;
import com.appcheck.recording.plugin.AbstractActionConverter;

public final class TouchAction extends DefaultAction implements AbstractAction, ActionConvert {

	private View view;
	private int actionCode;
	private float x;
	private float y;
	private int touchTime;
	private long catchTime;
	private IdNamePair[] preViewArray;
	
	public final String toString(){
		JSONObject localJSONObject = new JSONObject();
	    try{
	      localJSONObject.put("class", "TouchAction");
	      localJSONObject.put("x", (int)this.x);
	      localJSONObject.put("y", (int)this.y);
	      localJSONObject.put("touchTime", this.touchTime);
	      localJSONObject.put("index", this.index);
	      localJSONObject.put("id", this.resourceId);
	      localJSONObject.put("name", this.resourceName);
	      if(preViewArray != null){
		    JSONArray jsonArray = new JSONArray();
		    for(IdNamePair pair : preViewArray){
		    	JSONObject idNamePair = new JSONObject();
		    	idNamePair.put("resourceName", pair.getResourceName());
		    	idNamePair.put("resourceId", pair.getResourceId());
		    	jsonArray.put(idNamePair);
		    }
		    localJSONObject.put("preViewList", jsonArray);
	      }
	    }
	    catch (JSONException localJSONException) {}
	    return localJSONObject.toString();
	}
	
	@Override
	public boolean handle(AbstractActionHandler actionHandler) {
		return actionHandler.visit(this);
	}

	public final View getView() {
		return view;
	}

	public final void setView(View view) {
		this.view = view;
	}

	public final int getActionCode() {
		return actionCode;
	}

	public final void setActionCode(int actionCode) {
		this.actionCode = actionCode;
	}

	public final float getX() {
		return x;
	}

	public final void setX(float x) {
		this.x = x;
	}

	public final float getY() {
		return y;
	}

	public final void setY(float y) {
		this.y = y;
	}

	public final void setTouchTime(int touchTime) {
		this.touchTime = touchTime;
	}

	public final long getCatchTime() {
		return catchTime;
	}

	public final void setCatchTime(long catchTime) {
		this.catchTime = catchTime;
	}

	@Override
	public void toTestCode(AbstractActionConverter actionConverter) {
		actionConverter.convert(this);
	}

}
